package com.example.androidmpcharts.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.widget.TextView;

import com.example.androidmpcharts.R;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;

public class LineChartMarkView extends MarkerView {

    private TextView tvDate;
    private TextView tvValue;
    private ValueFormatter xAxisValueFormatter;
    private ValueFormatter yAxisValueFormatter;

    public LineChartMarkView(Context context,ValueFormatter xAxisValueFormatter,ValueFormatter yAxisValueFormatter) {
        super(context, R.layout.layout_line_mark_view);
        this.xAxisValueFormatter = xAxisValueFormatter;
        this.yAxisValueFormatter = yAxisValueFormatter;

        tvDate = findViewById(R.id.tv_date);
        tvValue = findViewById(R.id.tv_value);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void refreshContent(Entry e, Highlight highlight) {
        //展示自定义X轴值 后的X轴内容
        tvDate.setText(xAxisValueFormatter.getAxisLabel(e.getX(), null));
        tvValue.setText("我的收益：" +yAxisValueFormatter.getAxisLabel(e.getY(),null));
        super.refreshContent(e, highlight);
    }

    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth() / 2), -getHeight());
    }
}